import 'package:flutter/material.dart';
import 'package:huajianshe_app/base/AppNavigator.dart';
import 'package:huajianshe_app/base/BaseState.dart';
import 'package:huajianshe_app/common/res.dart';
import 'package:huajianshe_app/widget/RoundedCornerWidget.dart';
import 'package:huajianshe_app/widget/SmartButton.dart';

class YesOrNoDialog extends StatefulWidget {

  final String? title, content, yesText, noText;
  final void Function()? onConfirm, onCancel;

  const YesOrNoDialog(this.content, {Key? key,
    this.title = '提示',
    this.yesText = '确定',
    this.noText = '取消',
    this.onConfirm,
    this.onCancel
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _YesOrNoDialogState();
  }
}

class _YesOrNoDialogState extends BaseState<YesOrNoDialog> {
  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(0),
      ),
      elevation: 0,
      backgroundColor: Colors.transparent,
      child: buildChild(context),
    );
  }

  Widget buildChild(BuildContext context) {
    return RoundedCornerWidget(borderWidth: 0, radius: 13, 
        gradient: LinearGradient(colors: [Color(0xFFFFEBED), Color(0xFFFFFFFF)], 
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter),
        child: Column(mainAxisSize: MainAxisSize.min, children: [
          H(38),
          Text('${widget.title}', style: TS(17, C.gray333, fontWeight: FontWeight.bold)),
          H(10),
          Text('${widget.content}', style: TS(15, C.gray666)),
          H(25),
          Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
            SmartButton(width: 130, height: 40, radius: 20, text: '${widget.yesText}', fontSize: 15, textColor: Colors.white,
            onPressed: widget.onConfirm,),
            SmartButton(width: 130, height: 40, radius: 20, text: '${widget.noText}', fontSize: 15, textColor: C.primary,
              backgroundColor: Colors.transparent,
              onPressed: () {widget.onCancel == null ? AppNavigator.pop(context) : widget.onCancel!(); })
          ],),
          H(23)
        ])
    );
  }
}